package com.example.blog.model;

import com.example.blog.enums.ResultCode;
import lombok.Data;

@Data
public class Result<T> {
    private ResultCode code;
    private String errorMsg;
    private T data;

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.code = ResultCode.SUCCESS;
        result.errorMsg = "";
        result.data = data;
        return result;
    }

    public static <T> Result<T> failure(String errorMsg){
        Result<T> result = new Result<>();
        result.code = ResultCode.FAILURE;
        result.errorMsg = errorMsg;
        result.data = null;
        return result;
    }

    public static <T> Result<T> failure(String errorMsg, T data){
        Result<T> result = new Result<>();
        result.code = ResultCode.FAILURE;
        result.errorMsg = errorMsg;
        result.data = data;
        return result;
    }
}
